package cn.springBoot;


import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.repository.ProcessDefinition;
import org.camunda.bpm.engine.rest.impl.CamundaRestResources;
import org.camunda.bpm.spring.boot.starter.annotation.EnableProcessApplication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

@SpringBootApplication
@ServletComponentScan
@EnableProcessApplication
public class SpringbootMyBatiesPlusDruidApplication implements CommandLineRunner {
	private final Logger logger = LoggerFactory.getLogger(SpringbootMyBatiesPlusDruidApplication.class);

	public static void main(String[] args) {
		SpringApplication.run(SpringbootMyBatiesPlusDruidApplication.class, args);
	}

	@Autowired
	RepositoryService repositoryService;

	@Override
	public void run(String... args) throws Exception {
		List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery().active().latestVersion().list();
		logger.info("> 处于激活状态的最新版本的流程定义数量: " + processDefinitionList.size());
		for (ProcessDefinition pd : processDefinitionList) {
			logger.info("\t ===> Process definition: " + pd.getKey() + " 版本：" + pd.getVersion());
		}

	}

	public Set<Class<?>> getClasses() {
		Set<Class<?>> classes = new HashSet<Class<?>>();
		// add your own classes

		// add all camunda engine rest resources (or just add those that you actually need).
		classes.addAll(CamundaRestResources.getResourceClasses());

		// mandatory
		classes.addAll(CamundaRestResources.getConfigurationClasses());

		return classes;
	}

}
